package dao.mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import conexion.BDConexion;
import beans.Distrito;
import dao.interfaces.DistritoDAO;

public class MySqlDistritoDAO implements DistritoDAO {
	
	@Override
	public List<Distrito> ListarDistrito() {
		List<Distrito> lista = new ArrayList<Distrito>();
		Connection cn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			cn = new BDConexion().obtenerConexion();
			String sql = "SELECT * FROM bd_inictel_dcc.distrito;";
			pst = cn.prepareStatement(sql);
			rs = pst.executeQuery();
			while (rs.next()) {
				Distrito d = new Distrito(rs.getInt(1), rs.getString(2));
				lista.add(d);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				cn.close();
				pst.close();
				rs.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return lista;
	}

}
